/*
 * SPI.h
 *
 *  Created on: Jan 20, 2012
 *      Author: Administrator
 */

#ifndef SPI_H_
#define SPI_H_

#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#define __AVR_ATmega328P__


#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07

#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C

#if defined(__AVR_ATmega1284P__)

#define SPI_PORT PORTB
#define SPI_DDR	 DDRB

#define SS_bp 	4
#define MOSI_bp 5
#define MISO_bp 6
#define SCK_bp	7
#define SS_bm	0x10
#define MOSI_bm 0x20
#define MISO_bm 0x40
#define SCK_bm	0x80

#elif defined(__AVR_ATmega328P__)

#define SPI_PORT PORTB
#define SPI_DDR	 DDRB

#define SS_bp 	2
#define MOSI_bp 3
#define MISO_bp 4
#define SCK_bp	5
#define SS_bm	0x04
#define MOSI_bm 0x08
#define MISO_bm 0x10
#define SCK_bm	0x20


#endif


void initSPI();
uint8_t readSPI();
void writeSPI(uint8_t data);
uint8_t transferSPI(uint8_t data);


#endif /* SPI_H_ */
